# 染色体选择
import random
from src.ga.evaluator import fitness


def stochastic_tournament(group, operator, pattern='MRE', tested='tf'):
    k = len(group)
    new_group = []
    for t in range(k):
        index1 = random.randint(0, k - 1)
        index2 = random.randint(0, k - 1)
        if fitness(group[index1], operator, pattern, tested) >= fitness(group[index2], operator, pattern, tested):
            new_group.append(group[index1])
        else:
            new_group.append(group[index2])
    return new_group
